<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style type="text/css">
    .el-main{
        position: absolute;
        top: 70px;
        bottom: 0px;
        left: 200px;
        right: 10px;
        padding: 0;
    }
    </style>
</head>
<body class="hold-transition skin-purple sidebar-mini">
    <div id="app">

        <!-- 修改密码弹层 -->
        <div class="add-form">
            <el-dialog title="修改登陆密码" :visible.sync="dialogFormVisible">
                <template>
                    <el-tabs v-model="activeName" type="card">
                        <el-tab-pane label="用户信息"  name="first">
                            <el-form ref="dataAddForm" label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="新密码">
                                            <el-input v-model="password"/>
                                        </el-form-item>
                                    </el-col>

                                </el-row>


                                <el-row>

                                    <el-col :span="12">
                                        <el-form-item label="确认新密码">
                                            <el-input v-model="repassword"/>
                                        </el-form-item>
                                    </el-col>

                                </el-row>


                                <el-row>

                                    <el-col :span="12">

                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <span style="text-align: center;color: red;" v-html="error"></span>

                                    </el-col>

                                </el-row>
                                <el-row>
                                </el-row>
                            </el-form>
                        </el-tab-pane>
                    </el-tabs>
                </template>
                <div slot="footer" class="dialog-footer" style="text-align: center">
                    <el-button @click="dialogFormVisible = false">取消</el-button>
                    <el-button type="primary" @click="update()">确定</el-button>
                </div>
            </el-dialog>
        </div>


        <el-container>
            <el-header  class="main-header" style="height:70px;">
                <nav class="navbar navbar-static-top" :class=''>
                    <!-- Logo -->
                    <a href="#" class="logo" style="text-align:center">
                        <span class="logo-lg"><img src="../img/logo.png"></span>
                    </a>
                    <div class="right-menu">
                        <span class="help"><i class="fa fa-exclamation-circle" aria-hidden="true"></i>帮助</span>
                        <el-dropdown class="avatar-container right-menu-item" trigger="click">
                            <div class="avatar-wrapper">
                                <img src="../img/user2-160x160.jpg" class="user-avatar">
                                <span v-html="username"></span>
                            </div>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item divided>
                                    <span style="display:block;"><a href="javascript:;" @click="dialogFormVisible=true">修改密码</a></span>
                                </el-dropdown-item>
                                <el-dropdown-item divided>
                                        <span style="display:block;">

                                            <a href="/logout">退出</a>

                                        </span>
                                    </el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </div>
                </nav>
            </el-header>
            <el-container>
                <el-aside width="200px">
                    <el-menu>
                        <el-submenu v-for="menu in menuList" :index="menu.path">
                            <template slot="title">
                                <i class="fa" :class="menu.icon"></i>
                                {{menu.name}}
                            </template>
                            <template v-for="child in menu.children">
                                <el-menu-item :index="child.path">
                                    <a :href="child.linkUrl" target="right">{{child.name}}</a>
                                </el-menu-item>
                            </template>
                        </el-submenu>
                    </el-menu>
                </el-aside>
                <el-container>
                    <iframe name="right" class="el-main" src="checkitem.html" width="100%" height="580px" frameborder="0"></iframe>
                </el-container>
            </el-container>
        </el-container>
    </div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    new Vue({
        el: '#app',
        data:{
            password:"",
            repassword:"",
            error:"",
            dialogFormVisible:false,
            activeName:'first',//添加/编辑窗口Tab标签名称
            username:"",
            menuList:[

            ]
        },
        methods:{
            update() {
                if (this.password==null||this.password==""){
                    this.error="新密码不能为空"
                    return false;
                }
                if (this.password.length<6||this.password.length>12){
                    this.error="新密码长度6-12位"
                    return false;
                }
                if (this.password!=this.repassword){
                    this.error="两次密码输入不一致"
                    return false;
                }
                axios.post("/user/updatePassword/"+this.username+"/"+this.password).then(resp=>{

                    if (resp.data.flag){
                        this.$message({
                            type:'success',
                            message:resp.data.message
                        })
                        setTimeout(function () {
                            window.location.href="/logout"
                        },3000)
                    }
                    else{
                        this.$message.error(resp.data.message)
                    }

                }).finally(resp=>{
                    this.dialogFormVisible=false
                    this.error=""
                })

          }
        },
        created(){
            //获取当前登陆用户名
            axios.get("/user/getUsername").then(resp=>{
                if (resp.data.flag){
                    this.username=resp.data.data
                } else {
                    this.$message.error(resp.data.message)
                }
            })


            //根据当前登陆用户查询显示菜单
            axios.get("/user/showMenu").then(resp=>{
                if (resp.data.flag){
                    this.menuList=resp.data.data
                } else{
                    this.$message.error(resp.data.message)
                }
            })

        }
    });
    $(function() {
            var wd = 200;
            $(".el-main").css('width', $('body').width() - wd + 'px');
    });
</script>
</html>
